package com.xingda.packing.dmss.shunt.listener;

import com.xingda.packing.dmss.domain.ShuntProductionLine;
import com.xingda.packing.dmss.enums.TaskState;
import com.xingda.packing.dmss.enums.TaskType;
import com.xingda.packing.dmss.shunt.ticket.ShuntTicket;
import org.springframework.stereotype.Component;

@Component
public class ShuntListener implements TaskListenerService {
    @Override
    public boolean accept(ShuntProductionLine productionLine) {
        return checkTask(productionLine.getTaskTicket(), TaskType.SHUNT);
    }

    @Override
    public void monitor(ShuntProductionLine productionLine) {
        //是否分流完成
        if (productionLine.isShuntOver()) {
            //重置点位
            productionLine.restartShuntAreaSignal();
            ShuntTicket taskTicket = (ShuntTicket) productionLine.getTaskTicket();
            productionLine.getShuntArea().addWheelToSql(taskTicket.getWheel(), taskTicket.getLocation());
            taskTicket.setState(TaskState.FINISH);
            productionLine.listenerShuntEvent(taskTicket);
        }
    }
}
